package com.dog.basics.admin.controller.common;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dog.basics.bean.dto.admin.common.NewsAddDto;
import com.dog.basics.bean.dto.admin.common.NewsEditDto;
import com.dog.basics.bean.dto.admin.common.NewsFromDto;
import com.dog.basics.bean.vo.admin.common.NewsVo;
import com.dog.basics.common.annotation.SysLog;
import com.dog.basics.common.constant.SwaggerConstants;
import com.dog.basics.common.util.PageParam;
import com.dog.basics.common.util.R;
import com.dog.basics.service.common.IDogNewsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 消息通知 前端控制器
 * </p>
 *
 * @author guonh
 * @since 2020-05-14
 */
@RestController
@RequestMapping("/admin/news")
@Api(value = SwaggerConstants.COMMON+"消息通知模块", tags = SwaggerConstants.COMMON+"消息通知模块")
@AllArgsConstructor
public class DogNewsController {
    private final IDogNewsService dogNewsService;

    /**
     * @Description: 消息通知列表
     * @Param: status
     * @return: IPage<NewsVo>
     * @Author: wph
     * @Date:
     */
    @ApiOperation(value = "消息通知列表", notes = "pc:news:page")
    @GetMapping("/page")
    @PreAuthorize("@pms.hasPermission('pc:news:page')")
    public R<IPage<NewsVo>> page(PageParam page, NewsFromDto obj) {
        IPage<NewsVo> list = dogNewsService.getPageList(page, obj);
        return R.ok(list);
    }

    /**
     * @Description: 增加消息通知
     * @Param: PlateAddDto
     * @return: Boolean
     * @Author: wph
     * @Date: 2020/05/19  0027
     */
    @SysLog("增加消息通知")
    @ApiOperation(value = "增加消息通知", notes = "pc:news:save")
    @PostMapping("/save")
    @PreAuthorize("@pms.hasPermission('pc:news:save')")
    public R<Boolean> save(@Valid @RequestBody NewsAddDto obj) {
        return R.ok(dogNewsService.saveObj(obj));
    }

    /**
     * @Description: 删除消息通知
     * @Param: ids
     * @return: Boolean
     * @Author: wph
     * @Date: 2020/05/19  0027
     */
    @SysLog("删除消息通知")
    @ApiOperation(value = "删除消息通知", notes = "pc:news:delete")
    @ApiImplicitParam(value = "消息通知Id", name = "id", dataType = "Long", required = true)
    @DeleteMapping("/delete/{id}")
    @PreAuthorize("@pms.hasPermission('pc:news:delete')")
    public R<Boolean> delete(@PathVariable("id") Long id) {
        return R.ok(dogNewsService.deleteObj(id));
    }

    /**
     * @Description: 修改消息通知
     * @Param: PlateEditDto
     * @return: Boolean
     * @Author: wph
     * @Date: 2020/05/19  0027
     */
    @SysLog("修改消息通知")
    @ApiOperation(value = "修改消息通知", notes = "pc:news:edit")
    @PutMapping("/edit")
    @PreAuthorize("@pms.hasPermission('pc:news:edit')")
    public R<Boolean> edit(@Valid @RequestBody NewsEditDto obj) {
        return R.ok(dogNewsService.editObj(obj));
    }
}
